<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item v-for="item in breadList" :key="item.path" :to="{ path: item.path }">{{item.meta.name}}</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <router-view></router-view>
    </el-card>

  </div>

</template>

<script>
export default {
  name: 'homeRight',
  data() {
    return {
      breadList: [] // 路由集合
    }
  },
  watch: {
    $route() {
      this.getBreadcrumb()
    }
  },
  methods: {
    isHome(route) {
      return route.path === '/home'
    },
    getBreadcrumb() {
      let matched = this.$route.matched
      // 如果不是首页
      if (!this.isHome(matched[0])) {
        matched = [{ path: '/home', meta: { title: '首页' } }].concat(matched)
      }
      this.breadList = matched
    }
  },
  created() {
    this.getBreadcrumb()
  }
}
</script>

<style lang="less" scoped>
.box-card {
  margin-top: 15px;
}
</style>
